<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.cp.vo.CpInfoDTO" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.admin.tags.PageModel" %>
<%@ page import="com.qipay.admin.utils.SiteHelper" %>
<%@ page import="com.qipay.baas.model.Cp" %>
<%@ page import="com.qipay.baas.model.CpAccount" %>
<%@ page import="com.qipay.baas.model.User" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="com.qipay.baas.model.CpZhiding" %>
<!doctype html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/list.css">
    <script type="text/javascript">
        document.getElementsByTagName("html")[0].style.fontSize=screen.availWidth/200+"px";
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">商户列表</h3>
                        </div>
                        <div style="clear: both"></div>
                        <!-- /.box-header -->
                        <div class="tableContent">
                            <form action="/sp/zhidingCp/save" method="POST" id="saveForm">
                            <table  width="100%" cellpadding="0" cellspacing="0" border="1">
                                <thead>
                                <tr>

                                    <th width="10%">商户ID</th>
                                    <th width="20%">商户名称</th>
                                    <th width="18%">
                                        代理商ID
                                        <select name="agentId" id="selectselect" onchange="changeAgent();">
                                            <option value="0">终端</option>
                                            <%
                                                int agentId = (int) request.getAttribute("agentId");
                                                int spChannelId = (int) request.getAttribute("spChannelId");
                                                List<Cp> agents = (List<Cp>) request.getAttribute("agents");
                                                if(agents!=null){
                                                    Iterator<Cp> iter = agents.iterator();
                                                    Cp aa = null;
                                                    while (iter.hasNext()) {
                                                        aa = iter.next();
                                                        String flag = "";
                                                        if(agentId==aa.getId())flag = "selected='selected'";
                                                         %>
                                                    <option <%=flag%> value="<%=aa.getId()%>"><%=aa.getId()%></option>
                                                <%}
                                                }
                                            %>

                                        </select>
                                    </th>
                                    <th width="10%">
                                        <input type="checkbox" id="inlineCheckbox1" style="zoom:150%;position:relative;top:3px;">
                                        <input type="button" id="selectall" class="btn btn-default" value="全选" />
                                    </th>
                                    <th width="8%"></th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<CpZhiding> articles = (List<CpZhiding>) request.getAttribute("cpZhidings");
                                    List<Integer> cpIds = (List<Integer>) request.getAttribute("cpIds");

                                    if (articles != null && articles.size() > 0) {
                                        Iterator<CpZhiding> iter = articles.iterator();
                                        CpZhiding user = null;
                                        while (iter.hasNext()) {
                                            user = iter.next();
                                            String flag = "";
                                            if (cpIds.contains(user.getId()))flag="checked='checked'";
                                %>
                                <tr id="user_<%=user.getId()%>">
                                    <td>
                                        <%=user.getId()%>
                                    </td>
                                    <td>
                                        <%=user.getName()%>
                                    </td>
                                    <td>
                                        <%=user.getAgentId()%>
                                    </td>
                                    <th width="20%">
                                        <input <%=flag%> name="cpIds" type="checkbox" style="zoom:140%;" value="<%=user.getId()%>">
                                    </th>
                                    <td>
                                        <button type="button" class="button back-gray" style="font-size: 1rem">美观</button>
                                    </td>

                                </tr>
                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="5">未找到数据</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                            <input name="spChannelId" type="hidden" value="<%=spChannelId%>">
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <button type="submit" class="btn btn-primary" id="btnSubmit" style="float: right;margin-right: 4%;width: 100px;color: #778899;">提交</button>
     </section>
    </div>
<jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.slimscroll.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>

<script>
    function changeAgent(){
        var agentId = $('#selectselect').val();
        window.location.href="/sp/zhidingCp?agentId="+agentId+"&spChannelId="+"<%=spChannelId%>";
    }
    $('#inlineCheckbox1').click(function(){
        var choose = $(this).prop("checked");
        if(choose){
            $("#selectall").click();
        }else{
            $("input:checkbox").prop("checked",false);
        }
    });
    $('#selectall').click(function(){
        $("input:checkbox").each(function () {
            $(this).prop('checked', true);//
        });
    });
    $('#btnSubmit').click(function(){
        $('#saveForm').submit();
    });
</script>
</body>
</html>

